package github.hotstu.camerax.qrcodec

import android.content.Context
import android.content.res.Configuration
import android.content.res.Resources
import android.util.TypedValue

/*
 * @author hope.chen, QQ:77132995, email:kazeik@163.com
 * 2021-04-28 13:26
 * 类说明:
 */
object Utils {
    fun formatType(format: Int): String {
        return when (format) {
            0 -> "FORMAT_ALL_FORMATS"
            1 -> "FORMAT_CODE_128"
            2 -> "FORMAT_CODE_39"
            4 -> "FORMAT_CODE_93"
            8 -> "FORMAT_CODABAR"
            16 -> "FORMAT_DATA_MATRIX"
            32 -> "FORMAT_EAN_13"
            64 -> "FORMAT_EAN_8"
            128 -> "FORMAT_ITF"
            256 -> "FORMAT_QR_CODE"
            512 -> "FORMAT_UPC_A"
            1024 -> "FORMAT_UPC_E"
            2048 -> "FORMAT_PDF417"
            4096 -> "FORMAT_AZTEC"
            else -> "FORMAT_UNKNOWN"
        }
    }

    /**
     * dp转px
     */
    fun Float.toPx(): Int {
        val resources = Resources.getSystem()
        return TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP,
            this,
            resources.displayMetrics
        ).toInt()
    }


    fun isPortraitMode(context: Context) : Boolean{
        val mConfiguration: Configuration = context.resources.configuration //获取设置的配置信息
        return mConfiguration.orientation == Configuration.ORIENTATION_PORTRAIT
    }
}
//
//const val FORMAT_UNKNOWN = -1
//const val FORMAT_ALL_FORMATS = 0
//const val FORMAT_CODE_128 = 1
//const val FORMAT_CODE_39 = 2
//const val FORMAT_CODE_93 = 4
//const val FORMAT_CODABAR = 8
//const val FORMAT_DATA_MATRIX = 16
//const val FORMAT_EAN_13 = 32
//const val FORMAT_EAN_8 = 64
//const val FORMAT_ITF = 128
//const val FORMAT_QR_CODE = 256
//const val FORMAT_UPC_A = 512
//const val FORMAT_UPC_E = 1024
//const val FORMAT_PDF417 = 2048
//const val FORMAT_AZTEC = 4096
//const val TYPE_UNKNOWN = 0
//const val TYPE_CONTACT_INFO = 1
//const val TYPE_EMAIL = 2
//const val TYPE_ISBN = 3
//const val TYPE_PHONE = 4
//const val TYPE_PRODUCT = 5
//const val TYPE_SMS = 6
//const val TYPE_TEXT = 7
//const val TYPE_URL = 8
//const val TYPE_WIFI = 9
//const val TYPE_GEO = 10
//const val TYPE_CALENDAR_EVENT = 11
//const val TYPE_DRIVER_LICENSE = 12